<?php
header('Content-Type:text/html;charset=utf-8');
require_once('include/config.php');
require_once('include/wp-db.php');
require_once('include/utils.php');

$time=time();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>汉庭海友客栈</title>
<link href="css/style.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="js/jquery-1.6.2.min.js"></script>
<script type="text/javascript" src="js/jquery.jcarousel.min.js"></script>
<script type="text/javascript">
/**
 * Item html creation helper.图片
 */

function mycarousel_itemLoadCallback(carousel, state)
{
	// 检查请求的项目是否存在
		if (carousel.has(carousel.first, carousel.last)) {
			return;
		}
		jQuery.get(
			'function/products_xml.php',	{
				type :'<?php echo $gettid?>',
				first: carousel.first,
				last: carousel.last
			},
			function(xml) {
				mycarousel_itemAddCallback(carousel, carousel.first, carousel.last, xml);
			},
			'xml'
		);
};

function mycarousel_itemAddCallback(carousel, first, last, xml){
		// 设置传送项的个数
		carousel.size(parseInt(jQuery('total', xml).text()));
	
		jQuery('data', xml).each(function(i) {
			var geturl=$(this).find("image").text();
			var gettitle=$(this).find("title").text();
			var getname="photo.php";
			carousel.add(first + i, mycarousel_getItemHTML(geturl,gettitle,getname));
		});
	};

/**
	 * Item html creation helper.
	 */
	function mycarousel_getItemHTML(url,title,name){
		return '<a href="'+name+'"><img  src="upload/photo/' + url + '" />'+title+'</a>';
	};
$(document).ready(function() {
	$('.jcarousel-skin').jcarousel({
	//	size: mycarousel_itemList.length,
	//	itemLoadCallback: {onBeforeAnimation: mycarousel_itemLoadCallback}
		
		 scroll: 4,
		 wrap: 'last',
		itemLoadCallback: mycarousel_itemLoadCallback
		
		
	});
	$('.gtl').click(function(){
		$("#login").before("<div id='exposeMask' style='*height:"+$("body").height()+"px'></div>");
		$("#login").show();
    });
	$('.close').click(function(){
		$("#exposeMask").remove();
		$("#login").hide();
    });
	
	
		countDown();
});


 var NowTime = new Date();

				  //计算出服务器和客户端的时间差。
 var dTime = <?php echo   $time*1000 ;?>-NowTime.getTime();
function countDown(){
	var all = $("input[id^='item_ids_']");
	for (i=0; i< all.length; i++)
	{
		var id = all[i].value;
		
	   var NowTime = new Date();
	   var sutime= NowTime.getTime();
	   var lasttime = $("#lasttime_" + id).val();
	   var starttime= $("#stime_" + id).val();
	   var showtime=$("#showtime_" + id).val();
		
	    lasttime=lasttime*1000;
		
	//	alert(starttime);
		
		var s_l_time=0;
		s_l_time=<?php echo  $time ;?>-starttime;
		
	    var nowtime = Date.parse(new Date());
		var time = lasttime- nowtime-dTime;
		var str='';
		
		if(s_l_time<=0)
		{
			str=showtime;
			$("#item_time_display_" + id).html(str);	
			
		}
		else if (Math.floor(time) <= 0)
		{
			$("#item_time_display_" + id).html('秒杀已结束');
		}
		else
		{
			var tday=Math.floor(time/(86400*1000));
			var thour=Math.floor(time/(3600*1000))%24;
			var totalhour=tday*24+thour;
			
			var tminute=Math.floor(time/(60*1000))%60;
			var tsecond=Math.floor(time/1000)%60;
			str="距离结束&nbsp;<em>"+totalhour+"</em>时<em>"+tminute+"</em>分<em>"+tsecond+"</em>秒";			
			$("#item_time_display_" + id).empty();
			$("#item_time_display_" + id).html(str);
		}
	}
	setTimeout('countDown()',1000);
}

</script>
</head>
<body>
<div id="header">
	<div class="logo"><a href="index.php"></a></div>
	<div class="menu">
		<ul>
			<li><a href="./"><img src="images/menu_1_.png" alt="首页" /></a></li>
			<li><a href="list.php"><img src="images/menu_2.png" alt="今日秒杀" /></a></li>
			<li><a href="next.php"><img src="images/menu_3.png" alt="下期预告" /></a></li>
			<li><a href="photo.php"><img src="images/menu_4.png" alt="客栈相册" /></a></li>
			<li><a href="qa.php"><img src="images/menu_5.png" alt="常见问题" /></a></li>
		</ul>
	</div>
	<div class="banner">
		<div class="nav">
			<ul>
				<li><a class="gtl"><img src="images/nav_login.png" /></a></li>
				<li><a href="./h/index.html"><img src="images/nav_hello.png" /></a></li>
				<li><a href="explain.php"><img src="images/nav_explain.png" /></a></li>
				<li><a href="http://www.htinns.com/hanting/KZDefault.aspx"  target="_blank"><img src="images/nav_website.png" /></a></li>
			</ul>
		</div>
		<div class="share">
			<a onclick="jiathis_sendto('tsina');return false;" style="cursor:pointer"><img src="images/ico_tsina.png" title="新浪微博" /></a>
			<a onclick="jiathis_sendto('tqq');return false;" style="cursor:pointer"><img src="images/ico_tqq.png" title="腾讯微博" /></a>
			<a onclick="jiathis_sendto('qzone');return false;" style="cursor:pointer"><img src="images/ico_qzone.png" title="QQ空间" /></a>
			<a onclick="jiathis_sendto('renren');return false;" style="cursor:pointer"><img src="images/ico_renren.png" title="人人网" /></a> 
			<a onclick="jiathis_sendto('douban');return false;" style="cursor:pointer"><img src="images/ico_douban.png" title="豆瓣" /></a>
			<a onclick="jiathis_sendto('kaixin001');return false;" style="cursor:pointer"><img src="images/ico_kaixin001.png" title="开心网" /></a>
			
			<script type="text/javascript">
				var jiathis_config = {
				url: "http://miaosha.htinns.com/",
				title: "海友客栈天天9元住,等你来秒!"
				
				}
			</script>
			
			
			<script type="text/javascript" src="js/share.js"></script> 
			
		</div>
	</div>
</div>
<div id="main" class="fix">

<div class="left">
		
		    <ul>
		<?php  
		$sql_next="select * from miao_cp  where nums>0 and  str_begintime>='$time'  and flag=1 order by id ASC  limit 6 ";
			
			$rs_next=$wpdb->get_results($sql_next);
			if($rs_next!=NULL)
			{
				foreach($rs_next as $next_v)
				{
					$id=$next_v->id;
					$subtitle=$next_v->subtitle;
					$miaoprice=$next_v->miaoprice;
					$begintime=$next_v->begintime;
					$endtime=$next_v->endtime;
					$imgpath=$next_v->imgpath;
					?>
      
			<li><a href="r_detail.php?d=<?php echo $id?>"><img src="upload/hotel/<?php echo $imgpath?>" /></a></li>
            
            <?php
				}
				
			}
			
			?>
		</ul>
        
	</div>
	
	<div class="right">
		<div style="padding:26px 0 0 16px;height:49px"><a href="list.php" class="more">查看更多 ▶</a><img src="images/tit_ms.png" /></div>
		<div class="ilist">
			<ul class="fix">
			<?php
            $sql_cp="select * from miao_cp  where nums>0 and str_endtime>='$time' and flag=1 order by id asc limit 6";
			
			$rs_cp=$wpdb->get_results($sql_cp);
			if($rs_cp!=NULL)
			{
				foreach($rs_cp as $cp_v)
				{
					$id=$cp_v->id;
					$subtitle=$cp_v->subtitle;
					$miaoprice=$cp_v->miaoprice;
					$begintime=$cp_v->begintime;
					$endtime=$cp_v->endtime;
					$imgpath=$cp_v->imgpath;
					$nowtime=time();
					$nums      =  $cp_v->nums;
					$str_begintime=$cp_v->str_begintime;
					$str_endtime=$cp_v->str_endtime;
					
					
					$rediturl='';
					$btnstr='';
					$datestr='';
					if(($nowtime)<=($str_begintime))
					{
						$rediturl='r_detail.php?d='.$id;	
						$btnstr='images/btn_jj.png';
						$datestr=0;	
						
						
					}
					elseif(($nowtime)>=($str_begintime) && ($nowtime)<=($str_endtime))
					{
						$rediturl='r_detail.php?d='.$id;
						$btnstr='images/btn_ms.png';	
						$datestr=1;			
					}
					else
					{
						$rediturl='r_detail.php?d='.$id;	
						$btnstr='images/btn_jj.png';
						$datestr=0;	
					}
					
					$month=date('m',$str_begintime);
					$day=date('d',$str_begintime);
					$hour=date('H',$str_begintime);
					
					$sql_nums="select count(*) from users_cp where cpid='$id'";
					$sub_nums=$wpdb->get_var($sql_nums);
					$sub_nums=intval($nums)-intval($sub_nums);
					
					
					if($sub_nums>0)
					{
					?>
                    <li>
					<a href="<?php echo $rediturl;?>" class="pic"><img src="upload/hotel/<?php echo $imgpath?>" /><span><?php echo $subtitle?></span></a>
					<span class="time">秒杀价<b>￥</b><strong><?php echo $miaoprice;?></strong>&nbsp;<label id="item_time_display_<?php echo $id?>"></label></span>
                    
                    <input id="lasttime_<?php echo $id?>" type="hidden" value="<?php echo $str_endtime;?>"/>
					<input id="item_ids_<?php echo $id?>" type="hidden" value="<?php echo $id?>"/>
               		<input id="stime_<?php echo $id?>" type="hidden" value="<?php echo $str_begintime?>"/>
               		<input id="showtime_<?php echo $id?>" type="hidden" value="开始日期:<em><?php echo $month?></em>月<em><?php echo $day?></em>日<em><?php echo $hour;?></em>时"/>
                    
                    
                    
					<a href="<?php echo $rediturl;?>" class="price"><img src="<?php echo $btnstr;?>" alt="即刻秒杀" /></a>
				</li>
                    
                    <?php
					}
				}	
			}
			?>
			</ul>
		</div>
	</div>
</div>
<div class="mlist">
	<div class="jcarousel-skin">
		<ul>
			<!-- The content will be dynamically loaded in here -->
		</ul>
	</div>
</div>

<?php include('footer.php');?>
<?php include('logintemplate.php');?>
</body>
</html>
